#coding:utf-8

from flask_restful import Api, Resource
import xml.etree.ElementTree as ET
import requests

class Weather(Resource):
    def get(self,arg_province, arg_city):
        url = "http://flash.weather.com.cn/wmaps/xml/" + arg_province + ".xml"
        r = requests.get(url)
        r.encoding = 'utf-8' 
        #print(r.encoding)
        xml = r.text
        print(xml)
        root = ET.fromstring(xml)
        curr_weather = "未知"
        for city in root:
            #print(city.attrib)
            #city_name = city.attrib['cityname']
            pyName = city.attrib['pyName']
            if pyName == arg_city:
                curr_weather = city.attrib['stateDetailed']
                #curr_weather = curr_weather.encode("utf-8").decode("unicode_escape")
                print(curr_weather)
                break
        return curr_weather